<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/1/18
  Time: 15:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>登录</title>
</head>
<body>
<%
    pageContext.setAttribute("PATH", request.getContextPath());
%>

<form action="${PATH}/login?action=form_login" id="login_form">
    用户名<input type="text" name="userName">
    密码<input type="text" name="passWord">
    <input type="submit" value="提交">
    <input type="reset" value="重置">
</form>

<form action="#" id="login_form">
    用户名<input type="text" name="userName">
    密码<input type="text" name="passWord">
    <input type="submit" value="ajax提交" id="submit">
    <input type="reset" value="重置">
</form>

</body>
</html>
<script src="${PATH}/static/js/jquery.js"></script>
<script>
    $('submit').click(function () {
        login()
    })
    function login() {
        $.ajax({
            url:'${PATH}/ajaxLogin?action=ajax_login',
            type:'post',
            data:$('#login_form').serialize(),
            success:function(data){
                if (data.data){
                    alert("登录成功")
                } else{
                    alert("登录失败")
                }
            }
        })
    }
</script>
